package models.bill;

import models.UUIDModel;
import models.constants.DeletedStatus;
import models.enums.PaymentType;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.List;

/**
 * 账单流水记录
 * 解决统一账单 多种支付方式 对账问题
 */
@Entity
@Table(name = "bl_bill_payments")
public class BillPayment extends UUIDModel {

    /**
     * 所属账单
     */
    @JoinColumn(name = "bill_id")
    @ManyToOne
    public Bill bill;

    /**
     * 支付渠道
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "payment_type", length = 10)
    public PaymentType paymentType;

    /**
     * 支付金额
     */
    @Column(name = "amount")
    public BigDecimal amount;

    /**
     * 支付流水号
     */
    @Column(name = "pay_sequence", length = 50)
    public String paySquence;

    /**
     * 支付备注.
     */
    @Column(name = "pay_remark", length = 100)
    public String payRemark;

    /**
     * 根据Bill查询
     * @param billId
     * @return
     */
    public static List<BillPayment> loadByBillId(String billId){
        return BillPayment.find(" bill.id = ? and deleted = ? " , billId , DeletedStatus.UN_DELETED).fetch();
    }
}
